package com.cwt_taxi_xa.protocol.card;
import com.cwt_taxi_xa.protocol.CardUtil;
import com.cwt_taxi_xa.protocol.DeviceBiz;
import com.cwt_taxi_xa.protocol.card.cmd.AckCallBack;
import com.cwt_taxi_xa.protocol.card.cmd.CardInfoEF08;
import com.cwt_taxi_xa.protocol.card.cmd.CardSMInfoEF04;
import com.cwt_taxi_xa.util.AppLog;
import com.cwt_taxi_xa.util.TTsFunction;
import com.cwt_taxi_xa.util.Tools;

/**
 * 签退模式
 * @author Administrator
 *
 */
public class CardSignOffState extends CardBaseState{

	String OFFTAG  = "CardSignOffState";


	public CardSignOffState() {
		super();
	}

	@Override
	public void startAndRead() {
		// TODO Auto-generated method stub
		super.startAndRead();
	}

	@Override
	public void start() {
		AppLog.d(TAG, "start()");
		// TODO Auto-generated method stub
		addCmdArray();
		// 暂时不定时读卡
		super.start();
		//sendTsm905Data(0x0015, Tools.parseHexStr2Byte("00"));
		//SerialPortService.getInstance().sendSerialData2(CardUtil.cardjy2(Tools.int2Bytes2(0x0020, 2)));
	}

	@Override
	public void stop() {
		// TODO Auto-generated method stub
		super.stop();
	}

	/*
	 * 第一次读卡
	 */
	private void addCmdArray(){
		clearCmdArray();
		synchronized (cmdArray) {
			addCmd(new CardSMInfoEF04("sminfo" ,carAckCallBack,DeviceBiz.getCarNumberSingleLetter()));
			addCmd(new CardInfoEF08("info" ,carAckCallBack));
		}
	}

	AckCallBack carAckCallBack = new AckCallBack() {

		@Override
		public void moveNext() {
			// TODO Auto-generated method stub
			moveNextCmd();
		}

		@Override
		public void callBack(String cmdTAG, String[] dataArray) {
			// TODO Auto-generated method stub
			AppLog.d(TAG, "carAckCallBack callBack TAG:" + TAG);
			//基础信息 EF0B
			if("info".equals(cmdTAG)){
				//签退用到
				if(CardUtil.listener!=null){
					CardUtil.listener.onReadCard(dataArray[3]);
					clearCmdArray();
					stop();
					return;
				}
			}
			moveNextCmd();
		}

		@Override
		public void sendCmd(int cmd, String data) {
			// TODO Auto-generated method stub
			sendTsm905Data(cmd, Tools.parseHexStr2Byte(data));
		}

		@Override
		public void error(String cmdTAG,int code, String error) {
			// TODO Auto-generated method stub
			TTsFunction.speakText(error);
			AppLog.d(TAG, "carAckCallBack error TAG:" + TAG);
		}
	};

	@Override
	public void endCmd() {
		// TODO Auto-generated method stub

	}

	@Override
	public long delay() {
		// TODO Auto-generated method stub
		return 2000;
	}

	@Override
	public long peroid() {
		// TODO Auto-generated method stub
		return super.peroid();
	}

}
